﻿using System;
using System.Collections.Generic;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x020002FC RID: 764
	public class ArmyNeedsSuppliesIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002CC8 RID: 11464 RVA: 0x000BBE7F File Offset: 0x000BA07F
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002CC9 RID: 11465 RVA: 0x000BBE98 File Offset: 0x000BA098
		public void OnCheckForIssue(Hero hero)
		{
			if (this.ConditionsHold(hero))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnStartIssue), typeof(ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssue), IssueBase.IssueFrequency.VeryCommon, null));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssue), IssueBase.IssueFrequency.VeryCommon));
		}

		// Token: 0x06002CCA RID: 11466 RVA: 0x000BBEFC File Offset: 0x000BA0FC
		private bool ConditionsHold(Hero issueGiver)
		{
			return issueGiver.IsLord && issueGiver.MapFaction.IsKingdomFaction && issueGiver.PartyBelongedTo != null && issueGiver.PartyBelongedTo.Army != null && issueGiver.PartyBelongedTo.Army.ArmyOwner == issueGiver && issueGiver.PartyBelongedTo.Army.Cohesion > 80f;
		}

		// Token: 0x06002CCB RID: 11467 RVA: 0x000BBF5F File Offset: 0x000BA15F
		private IssueBase OnStartIssue(in PotentialIssueData pid, Hero issueOwner)
		{
			return new ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssue(issueOwner);
		}

		// Token: 0x06002CCC RID: 11468 RVA: 0x000BBF67 File Offset: 0x000BA167
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x04000D6E RID: 3438
		private const IssueBase.IssueFrequency ArmyNeedsSuppliesIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

		// Token: 0x04000D6F RID: 3439
		private const float QuestDurationInDays = 15f;

		// Token: 0x020005FB RID: 1531
		public class ArmyNeedsSuppliesIssue : IssueBase
		{
			// Token: 0x060047F4 RID: 18420 RVA: 0x0014E673 File Offset: 0x0014C873
			internal static void AutoGeneratedStaticCollectObjectsArmyNeedsSuppliesIssue(object o, List<object> collectedObjects)
			{
				((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x060047F5 RID: 18421 RVA: 0x0014E681 File Offset: 0x0014C881
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x060047F6 RID: 18422 RVA: 0x0014E68A File Offset: 0x0014C88A
			internal static object AutoGeneratedGetMemberValueNumberOfManInArmy(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssue)o).NumberOfManInArmy;
			}

			// Token: 0x17000E11 RID: 3601
			// (get) Token: 0x060047F7 RID: 18423 RVA: 0x0014E69C File Offset: 0x0014C89C
			private int GrainAmount
			{
				get
				{
					return MathF.Ceiling((float)(this.NumberOfManInArmy / 20) * 5f);
				}
			}

			// Token: 0x17000E12 RID: 3602
			// (get) Token: 0x060047F8 RID: 18424 RVA: 0x0014E6B3 File Offset: 0x0014C8B3
			private int LiveStockAmount
			{
				get
				{
					return MathF.Ceiling((float)(this.NumberOfManInArmy / 20) * 0.5f);
				}
			}

			// Token: 0x17000E13 RID: 3603
			// (get) Token: 0x060047F9 RID: 18425 RVA: 0x0014E6CA File Offset: 0x0014C8CA
			private int WineAmount
			{
				get
				{
					return MathF.Ceiling((float)(this.NumberOfManInArmy / 20) * 0.5f);
				}
			}

			// Token: 0x17000E14 RID: 3604
			// (get) Token: 0x060047FA RID: 18426 RVA: 0x0014E6E1 File Offset: 0x0014C8E1
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000E15 RID: 3605
			// (get) Token: 0x060047FB RID: 18427 RVA: 0x0014E6E4 File Offset: 0x0014C8E4
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000E16 RID: 3606
			// (get) Token: 0x060047FC RID: 18428 RVA: 0x0014E6E7 File Offset: 0x0014C8E7
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					return new TextObject("{=BW7v0g6q}We are about to go on campaign but my quartermaster reports that our food supplies will not be enough to keep us in the field for very long. I can't spare any of my lords, so I need someone else to bring us a large amount of supplies as soon as possible. Can you do this?[if:convo_grave][ib:closed]", null);
				}
			}

			// Token: 0x17000E17 RID: 3607
			// (get) Token: 0x060047FD RID: 18429 RVA: 0x0014E6F4 File Offset: 0x0014C8F4
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=YaZc08oa}I can bring supplies, your {?QUEST_GIVER.GENDER}ladyship{?}lordship{\\?}. Just tell me what you need.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000E18 RID: 3608
			// (get) Token: 0x060047FE RID: 18430 RVA: 0x0014E728 File Offset: 0x0014C928
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=444rcko0}We need {GRAIN_AMOUNT} sacks of grain to meet our basic needs. And if you can find {LIVESTOCK_AMOUNT} live stocks and {WINE_AMOUNT} barrels of wine that would be a great favor. Men fight better after a good meal.", null);
					textObject.SetTextVariable("GRAIN_AMOUNT", this.GrainAmount);
					textObject.SetTextVariable("LIVESTOCK_AMOUNT", this.LiveStockAmount);
					textObject.SetTextVariable("WINE_AMOUNT", this.WineAmount);
					return textObject;
				}
			}

			// Token: 0x17000E19 RID: 3609
			// (get) Token: 0x060047FF RID: 18431 RVA: 0x0014E778 File Offset: 0x0014C978
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=ppO0hoT6}I'll deliver {GRAIN_AMOUNT} sacks of grain as soon as possible {?QUEST_GIVER.GENDER}lady{?}sir{\\?}, and try to find some livestock and wine as you requested.", null);
					textObject.SetTextVariable("GRAIN_AMOUNT", this.GrainAmount);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000E1A RID: 3610
			// (get) Token: 0x06004800 RID: 18432 RVA: 0x0014E7BC File Offset: 0x0014C9BC
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=wVyqTlpS}Army Needs Supply", null);
				}
			}

			// Token: 0x17000E1B RID: 3611
			// (get) Token: 0x06004801 RID: 18433 RVA: 0x0014E7C9 File Offset: 0x0014C9C9
			public override TextObject Description
			{
				get
				{
					TextObject result = new TextObject("{=iMq7M0bo}{QUEST_GIVER.LINK} asks you to provide them supplies for their military campaign.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, null, false);
					return result;
				}
			}

			// Token: 0x06004802 RID: 18434 RVA: 0x0014E7EE File Offset: 0x0014C9EE
			public ArmyNeedsSuppliesIssue(Hero issueOwner) : base(issueOwner, CampaignTime.DaysFromNow(15f))
			{
				this.NumberOfManInArmy = base.IssueOwner.PartyBelongedTo.Army.TotalRegularCount;
			}

			// Token: 0x06004803 RID: 18435 RVA: 0x0014E81C File Offset: 0x0014CA1C
			protected override void OnGameLoad()
			{
			}

			// Token: 0x06004804 RID: 18436 RVA: 0x0014E81E File Offset: 0x0014CA1E
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004805 RID: 18437 RVA: 0x0014E820 File Offset: 0x0014CA20
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest(questId, base.IssueOwner, CampaignTime.DaysFromNow(15f), this.RewardGold, this.GrainAmount, this.LiveStockAmount, this.WineAmount);
			}

			// Token: 0x06004806 RID: 18438 RVA: 0x0014E850 File Offset: 0x0014CA50
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.VeryCommon;
			}

			// Token: 0x06004807 RID: 18439 RVA: 0x0014E854 File Offset: 0x0014CA54
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flags, out Hero relationHero, out SkillObject skill)
			{
				relationHero = null;
				skill = null;
				flags = IssueBase.PreconditionFlags.None;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flags |= IssueBase.PreconditionFlags.Relation;
					relationHero = issueGiver;
				}
				if (Hero.MainHero.IsKingdomLeader)
				{
					flags |= IssueBase.PreconditionFlags.MainHeroIsKingdomLeader;
				}
				if (issueGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					flags |= IssueBase.PreconditionFlags.AtWar;
				}
				if (Clan.PlayerClan.Tier < 1)
				{
					flags |= IssueBase.PreconditionFlags.ClanTier;
				}
				if (Clan.PlayerClan.Kingdom != issueGiver.MapFaction)
				{
					flags |= IssueBase.PreconditionFlags.NotInSameFaction;
				}
				return flags == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x06004808 RID: 18440 RVA: 0x0014E8ED File Offset: 0x0014CAED
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.ClanInfluence)
				{
					return -0.1f;
				}
				return 0f;
			}

			// Token: 0x06004809 RID: 18441 RVA: 0x0014E904 File Offset: 0x0014CB04
			public override bool IssueStayAliveConditions()
			{
				if (base.IssueOwner.PartyBelongedTo != null && base.IssueOwner.PartyBelongedTo.Army != null && base.IssueOwner.PartyBelongedTo.Army.ArmyOwner == base.IssueOwner && base.IssueOwner.PartyBelongedTo.Army.Cohesion > 40f && base.IssueOwner.Clan != Clan.PlayerClan && base.IssueOwner.MapFaction.IsKingdomFaction)
				{
					this.NumberOfManInArmy = base.IssueOwner.PartyBelongedTo.Army.TotalRegularCount;
					return true;
				}
				return false;
			}

			// Token: 0x0600480A RID: 18442 RVA: 0x0014E9AE File Offset: 0x0014CBAE
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x040018BC RID: 6332
			[SaveableField(70)]
			private int NumberOfManInArmy;
		}

		// Token: 0x020005FC RID: 1532
		public class ArmyNeedsSuppliesIssueQuest : QuestBase
		{
			// Token: 0x0600480B RID: 18443 RVA: 0x0014E9B0 File Offset: 0x0014CBB0
			internal static void AutoGeneratedStaticCollectObjectsArmyNeedsSuppliesIssueQuest(object o, List<object> collectedObjects)
			{
				((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x0600480C RID: 18444 RVA: 0x0014E9BE File Offset: 0x0014CBBE
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._grainLog);
				collectedObjects.Add(this._liveStockLog);
				collectedObjects.Add(this._wineLog);
			}

			// Token: 0x0600480D RID: 18445 RVA: 0x0014E9EB File Offset: 0x0014CBEB
			internal static object AutoGeneratedGetMemberValue_requestedGrainAmount(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o)._requestedGrainAmount;
			}

			// Token: 0x0600480E RID: 18446 RVA: 0x0014E9FD File Offset: 0x0014CBFD
			internal static object AutoGeneratedGetMemberValue_requestedLiveStockAmount(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o)._requestedLiveStockAmount;
			}

			// Token: 0x0600480F RID: 18447 RVA: 0x0014EA0F File Offset: 0x0014CC0F
			internal static object AutoGeneratedGetMemberValue_requestedWineAmount(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o)._requestedWineAmount;
			}

			// Token: 0x06004810 RID: 18448 RVA: 0x0014EA21 File Offset: 0x0014CC21
			internal static object AutoGeneratedGetMemberValue_currentGrainAmount(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o)._currentGrainAmount;
			}

			// Token: 0x06004811 RID: 18449 RVA: 0x0014EA33 File Offset: 0x0014CC33
			internal static object AutoGeneratedGetMemberValue_currentLiveStockAmount(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o)._currentLiveStockAmount;
			}

			// Token: 0x06004812 RID: 18450 RVA: 0x0014EA45 File Offset: 0x0014CC45
			internal static object AutoGeneratedGetMemberValue_currentWineAmount(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o)._currentWineAmount;
			}

			// Token: 0x06004813 RID: 18451 RVA: 0x0014EA57 File Offset: 0x0014CC57
			internal static object AutoGeneratedGetMemberValue_grainLog(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o)._grainLog;
			}

			// Token: 0x06004814 RID: 18452 RVA: 0x0014EA64 File Offset: 0x0014CC64
			internal static object AutoGeneratedGetMemberValue_liveStockLog(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o)._liveStockLog;
			}

			// Token: 0x06004815 RID: 18453 RVA: 0x0014EA71 File Offset: 0x0014CC71
			internal static object AutoGeneratedGetMemberValue_wineLog(object o)
			{
				return ((ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest)o)._wineLog;
			}

			// Token: 0x17000E1C RID: 3612
			// (get) Token: 0x06004816 RID: 18454 RVA: 0x0014EA7E File Offset: 0x0014CC7E
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000E1D RID: 3613
			// (get) Token: 0x06004817 RID: 18455 RVA: 0x0014EA81 File Offset: 0x0014CC81
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=wVyqTlpS}Army Needs Supply", null);
				}
			}

			// Token: 0x17000E1E RID: 3614
			// (get) Token: 0x06004818 RID: 18456 RVA: 0x0014EA90 File Offset: 0x0014CC90
			private TextObject _playerStartsQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=GiaTh92Q}{QUEST_GIVER.LINK}, commanding an army of the {QUEST_GIVER_FACTION}, has told you that they need food supplies for their upcoming military campaign. {?QUEST_GIVER.GENDER}She{?}He{\\?} wanted you to deliver {GRAIN_AMOUNT} sacks of grain and although it's not necessary, to provide {LIVESTOCK_AMOUNT} live stocks and {WINE_AMOUNT} barrels of wine {?QUEST_GIVER.GENDER}she{?}he{\\?} would appreciate it.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_GIVER_FACTION", base.QuestGiver.MapFaction.EncyclopediaLinkWithName);
					textObject.SetTextVariable("GRAIN_AMOUNT", this._requestedGrainAmount);
					textObject.SetTextVariable("LIVESTOCK_AMOUNT", this._requestedLiveStockAmount);
					textObject.SetTextVariable("WINE_AMOUNT", this._requestedWineAmount);
					return textObject;
				}
			}

			// Token: 0x17000E1F RID: 3615
			// (get) Token: 0x06004819 RID: 18457 RVA: 0x0014EB14 File Offset: 0x0014CD14
			private TextObject _successQuestLogText
			{
				get
				{
					return new TextObject("{=z9pbB0K5}You have successfully delivered the supplies as requested.", null);
				}
			}

			// Token: 0x17000E20 RID: 3616
			// (get) Token: 0x0600481A RID: 18458 RVA: 0x0014EB21 File Offset: 0x0014CD21
			private TextObject _failQuestLogText
			{
				get
				{
					return new TextObject("{=k5HJ3Ld6}You have failed to deliver the supplies in time.", null);
				}
			}

			// Token: 0x17000E21 RID: 3617
			// (get) Token: 0x0600481B RID: 18459 RVA: 0x0014EB30 File Offset: 0x0014CD30
			private TextObject _questCanceledWarDeclaredLog
			{
				get
				{
					TextObject textObject = new TextObject("{=vW6kBki9}Your clan is now at war with {QUEST_GIVER.LINK}'s realm. Your agreement with {QUEST_GIVER.LINK} is canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000E22 RID: 3618
			// (get) Token: 0x0600481C RID: 18460 RVA: 0x0014EB64 File Offset: 0x0014CD64
			private TextObject _playerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x0600481D RID: 18461 RVA: 0x0014EB96 File Offset: 0x0014CD96
			public ArmyNeedsSuppliesIssueQuest(string questId, Hero questGiver, CampaignTime duration, int rewardGold, int grainAmount, int liveStockAmount, int wineAmount) : base(questId, questGiver, duration, rewardGold)
			{
				this._requestedGrainAmount = grainAmount;
				this._requestedLiveStockAmount = liveStockAmount;
				this._requestedWineAmount = wineAmount;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x0600481E RID: 18462 RVA: 0x0014EBC7 File Offset: 0x0014CDC7
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
			}

			// Token: 0x0600481F RID: 18463 RVA: 0x0014EBCF File Offset: 0x0014CDCF
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004820 RID: 18464 RVA: 0x0014EBD4 File Offset: 0x0014CDD4
			protected override void SetDialogs()
			{
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(new TextObject("{=64RFlBFr}Very well. Don't worry, all your expenses will be covered.[if:convo_approving][ib:hip] ", null), null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(new TextObject("{=bGbSbqTG}Have you brought our supplies?", null), null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(delegate
				{
					this.CalculateAndUpdateRequestedItemsCountInPlayer(false);
				}).BeginPlayerOptions().PlayerOption(new TextObject("{=FmjZfigu}Yes. I have brought your grain, livestock and wine as you requested.", null), null).Condition(new ConversationSentence.OnConditionDelegate(this.CheckIfPlayerCollectedEverything)).NpcLine(new TextObject("{=UjS8JnH5}Splendid. I will never forget your service, my friend.", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.CollectedEverythingConsequence)).CloseDialog().PlayerOption(new TextObject("{=ISOHhXxW}Yes. I have brought your grain and wine as you requested.", null), null).Condition(new ConversationSentence.OnConditionDelegate(this.CheckIfPlayerCollectedGrainWine)).NpcLine(new TextObject("{=1atg831t}Thank you. Your service will be remembered.", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.CollectedGrainAndWineConsequence)).CloseDialog().PlayerOption(new TextObject("{=YbsVaZkb}Yes. I have brought your grain and livestock as you requested.", null), null).Condition(new ConversationSentence.OnConditionDelegate(this.CheckIfPlayerCollectedGrainLiveStock)).NpcLine(new TextObject("{=1atg831t}Thank you. Your service will be remembered.", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.CollectedGrainAndLiveStockConsequence)).CloseDialog().PlayerOption(new TextObject("{=m9a3ZalO}Yes. I have brought your grain as you requested.", null), null).Condition(new ConversationSentence.OnConditionDelegate(this.CheckIfPlayerCollectedGrain)).NpcLine(new TextObject("{=1atg831t}Thank you. Your service will be remembered.", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.CollectedGrainConsequence)).CloseDialog().PlayerOption(new TextObject("{=PAbVhuKi}Not yet. I'm still working on it.", null), null).NpcLine(new TextObject("{=AV5xVGM5}Good. We need them as soon as possible.[if:convo_undecided_open][ib:closed2]", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(MapEventHelper.OnConversationEnd)).CloseDialog().EndPlayerOptions().CloseDialog();
			}

			// Token: 0x06004821 RID: 18465 RVA: 0x0014EDE4 File Offset: 0x0014CFE4
			private void CollectedGrainConsequence()
			{
				GainRenownAction.Apply(Hero.MainHero, 2f, false);
				GainKingdomInfluenceAction.ApplyForGivingFood(Hero.MainHero, base.QuestGiver, 5f);
				this.RelationshipChangeWithQuestGiver = 2;
				int amount = DefaultItems.Grain.Value * this._requestedGrainAmount;
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, amount, false);
				MobileParty.MainParty.ItemRoster.AddToCounts(DefaultItems.Grain, -this._requestedGrainAmount);
				base.QuestGiver.PartyBelongedTo.ItemRoster.AddToCounts(DefaultItems.Grain, this._requestedGrainAmount);
				base.CompleteQuestWithSuccess();
				MapEventHelper.OnConversationEnd();
			}

			// Token: 0x06004822 RID: 18466 RVA: 0x0014EE84 File Offset: 0x0014D084
			private void CollectedGrainAndLiveStockConsequence()
			{
				GainRenownAction.Apply(Hero.MainHero, 2f, false);
				GainKingdomInfluenceAction.ApplyForGivingFood(Hero.MainHero, base.QuestGiver, 5f);
				this.RelationshipChangeWithQuestGiver = 3;
				int num = DefaultItems.Grain.Value * this._requestedGrainAmount;
				num += MBObjectManager.Instance.GetObject<ItemObject>("sheep").Value * this._requestedLiveStockAmount;
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, num, false);
				MobileParty.MainParty.ItemRoster.AddToCounts(DefaultItems.Grain, -this._requestedGrainAmount);
				base.QuestGiver.PartyBelongedTo.ItemRoster.AddToCounts(DefaultItems.Grain, this._requestedGrainAmount);
				this.RemoveLiveStocksFromPlayer();
				base.CompleteQuestWithSuccess();
				MapEventHelper.OnConversationEnd();
			}

			// Token: 0x06004823 RID: 18467 RVA: 0x0014EF48 File Offset: 0x0014D148
			private void CollectedGrainAndWineConsequence()
			{
				GainRenownAction.Apply(Hero.MainHero, 2f, false);
				GainKingdomInfluenceAction.ApplyForGivingFood(Hero.MainHero, base.QuestGiver, 5f);
				this.RelationshipChangeWithQuestGiver = 4;
				int num = DefaultItems.Grain.Value * this._requestedGrainAmount;
				num += MBObjectManager.Instance.GetObject<ItemObject>("wine").Value * this._requestedLiveStockAmount;
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, num, false);
				MobileParty.MainParty.ItemRoster.AddToCounts(DefaultItems.Grain, -this._requestedGrainAmount);
				base.QuestGiver.PartyBelongedTo.ItemRoster.AddToCounts(DefaultItems.Grain, this._requestedGrainAmount);
				ItemObject @object = MBObjectManager.Instance.GetObject<ItemObject>("wine");
				MobileParty.MainParty.ItemRoster.AddToCounts(@object, -this._requestedWineAmount);
				base.QuestGiver.PartyBelongedTo.ItemRoster.AddToCounts(@object, this._requestedWineAmount);
				base.CompleteQuestWithSuccess();
				MapEventHelper.OnConversationEnd();
			}

			// Token: 0x06004824 RID: 18468 RVA: 0x0014F04C File Offset: 0x0014D24C
			private void CollectedEverythingConsequence()
			{
				GainRenownAction.Apply(Hero.MainHero, 2f, false);
				GainKingdomInfluenceAction.ApplyForGivingFood(Hero.MainHero, base.QuestGiver, 8f);
				this.RelationshipChangeWithQuestGiver = 6;
				int num = DefaultItems.Grain.Value * this._requestedGrainAmount;
				num += MBObjectManager.Instance.GetObject<ItemObject>("wine").Value * this._requestedLiveStockAmount;
				num += MBObjectManager.Instance.GetObject<ItemObject>("sheep").Value * this._requestedLiveStockAmount;
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, num, false);
				MobileParty.MainParty.ItemRoster.AddToCounts(DefaultItems.Grain, -this._requestedGrainAmount);
				base.QuestGiver.PartyBelongedTo.ItemRoster.AddToCounts(DefaultItems.Grain, this._requestedGrainAmount);
				ItemObject @object = MBObjectManager.Instance.GetObject<ItemObject>("wine");
				MobileParty.MainParty.ItemRoster.AddToCounts(@object, -this._requestedWineAmount);
				base.QuestGiver.PartyBelongedTo.ItemRoster.AddToCounts(@object, this._requestedWineAmount);
				this.RemoveLiveStocksFromPlayer();
				base.CompleteQuestWithSuccess();
				MapEventHelper.OnConversationEnd();
			}

			// Token: 0x06004825 RID: 18469 RVA: 0x0014F174 File Offset: 0x0014D374
			private void RemoveLiveStocksFromPlayer()
			{
				int i = this._requestedLiveStockAmount;
				while (i > 0)
				{
					for (int j = 0; j < MobileParty.MainParty.ItemRoster.Count; j++)
					{
						ItemRosterElement itemRosterElement = MobileParty.MainParty.ItemRoster[j];
						if (!itemRosterElement.IsEmpty)
						{
							ItemObject item = itemRosterElement.EquipmentElement.Item;
							if (item.HasHorseComponent && item.HorseComponent.IsLiveStock)
							{
								if (i < itemRosterElement.Amount)
								{
									MobileParty.MainParty.ItemRoster.AddToCounts(item, -i);
									i = 0;
									break;
								}
								MobileParty.MainParty.ItemRoster.AddToCounts(item, -itemRosterElement.Amount);
								i -= itemRosterElement.Amount;
							}
						}
					}
				}
				base.QuestGiver.PartyBelongedTo.ItemRoster.AddToCounts(MBObjectManager.Instance.GetObject<ItemObject>("meat"), this._requestedLiveStockAmount * 2);
			}

			// Token: 0x06004826 RID: 18470 RVA: 0x0014F267 File Offset: 0x0014D467
			private bool CheckIfPlayerCollectedGrain()
			{
				return this._currentGrainAmount >= this._requestedGrainAmount;
			}

			// Token: 0x06004827 RID: 18471 RVA: 0x0014F27A File Offset: 0x0014D47A
			private bool CheckIfPlayerCollectedGrainLiveStock()
			{
				return this._currentGrainAmount >= this._requestedGrainAmount && this._currentLiveStockAmount >= this._requestedLiveStockAmount;
			}

			// Token: 0x06004828 RID: 18472 RVA: 0x0014F29D File Offset: 0x0014D49D
			private bool CheckIfPlayerCollectedGrainWine()
			{
				return this._currentGrainAmount >= this._requestedGrainAmount && this._currentWineAmount >= this._requestedWineAmount;
			}

			// Token: 0x06004829 RID: 18473 RVA: 0x0014F2C0 File Offset: 0x0014D4C0
			private bool CheckIfPlayerCollectedEverything()
			{
				return this._currentGrainAmount >= this._requestedGrainAmount && this._currentWineAmount >= this._requestedWineAmount && this._currentLiveStockAmount >= this._requestedLiveStockAmount;
			}

			// Token: 0x0600482A RID: 18474 RVA: 0x0014F2F4 File Offset: 0x0014D4F4
			private void QuestAcceptedConsequences()
			{
				base.StartQuest();
				base.AddLog(this._playerStartsQuestLogText, false);
				this.CalculateAndUpdateRequestedItemsCountInPlayer(true);
				this._grainLog = base.AddDiscreteLog(TextObject.Empty, new TextObject("{=yGxjOnYb}Collected Grain Amount", null), this._currentGrainAmount, this._requestedGrainAmount, null, false);
				this._liveStockLog = base.AddDiscreteLog(TextObject.Empty, new TextObject("{=aIxX2s8n}Collected Livestock Amount (Optional)", null), this._currentLiveStockAmount, this._requestedLiveStockAmount, null, false);
				this._wineLog = base.AddDiscreteLog(TextObject.Empty, new TextObject("{=ENS8Ig1o}Collected Wine Amount (Optional)", null), this._currentWineAmount, this._requestedWineAmount, null, false);
			}

			// Token: 0x0600482B RID: 18475 RVA: 0x0014F39C File Offset: 0x0014D59C
			protected override void RegisterEvents()
			{
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.PlayerInventoryExchangeEvent.AddNonSerializedListener(this, new Action<List<ValueTuple<ItemRosterElement, int>>, List<ValueTuple<ItemRosterElement, int>>, bool>(this.OnInventoryExchange));
				CampaignEvents.ArmyDispersed.AddNonSerializedListener(this, new Action<Army, Army.ArmyDispersionReason, bool>(this.OnArmyDispersed));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
			}

			// Token: 0x0600482C RID: 18476 RVA: 0x0014F408 File Offset: 0x0014D608
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (clan == Clan.PlayerClan && oldKingdom == base.QuestGiver.MapFaction)
				{
					TextObject textObject = new TextObject("{=aQVdW6aC}You have left {QUEST_GIVER_FACTION}. Your agreement with {QUEST_GIVER.LINK} is terminated.", null);
					textObject.SetTextVariable("QUEST_GIVER_FACTION", base.QuestGiver.MapFaction.EncyclopediaLinkWithName);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					base.CompleteQuestWithCancel(textObject);
					return;
				}
				if (base.QuestGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					base.CompleteQuestWithCancel(this._questCanceledWarDeclaredLog);
				}
			}

			// Token: 0x0600482D RID: 18477 RVA: 0x0014F49B File Offset: 0x0014D69B
			private void OnArmyDispersed(Army army, Army.ArmyDispersionReason reason, bool isPlayersArmy)
			{
				if (army.ArmyOwner == base.QuestGiver)
				{
					base.AddLog(new TextObject("{=K2gsZOMb}Army is disbanded and your mission was canceled.", null), false);
					base.CompleteQuestWithCancel(null);
				}
			}

			// Token: 0x0600482E RID: 18478 RVA: 0x0014F4C5 File Offset: 0x0014D6C5
			private void OnInventoryExchange(List<ValueTuple<ItemRosterElement, int>> purchasedItems, List<ValueTuple<ItemRosterElement, int>> soldItems, bool isTrading)
			{
				this.CalculateAndUpdateRequestedItemsCountInPlayer(true);
			}

			// Token: 0x0600482F RID: 18479 RVA: 0x0014F4D0 File Offset: 0x0014D6D0
			private void CalculateAndUpdateRequestedItemsCountInPlayer(bool notifyPlayer = true)
			{
				ItemObject grain = DefaultItems.Grain;
				ItemObject @object = MBObjectManager.Instance.GetObject<ItemObject>("wine");
				this._currentGrainAmount = MobileParty.MainParty.ItemRoster.GetItemNumber(grain);
				this._currentLiveStockAmount = MobileParty.MainParty.ItemRoster.NumberOfLivestockAnimals;
				this._currentWineAmount = MobileParty.MainParty.ItemRoster.GetItemNumber(@object);
				if (notifyPlayer)
				{
					if (this._currentGrainAmount >= this._requestedGrainAmount && this._currentLiveStockAmount >= this._requestedLiveStockAmount && this._currentWineAmount >= this._requestedWineAmount)
					{
						MBInformationManager.AddQuickInformation(new TextObject("{=uEV6kKdU}You have collected all the supplies that the army commander requested. Return to army and deliver the supplies", null), 0, null, "");
					}
					else if (this._currentGrainAmount >= this._requestedGrainAmount)
					{
						MBInformationManager.AddQuickInformation(new TextObject("{=8XpTvx1i}You have collected enough grains that the army commander requested. Return to army and deliver the supplies", null), 0, null, "");
					}
				}
				this._currentGrainAmount = (int)MathF.Clamp((float)this._currentGrainAmount, 0f, (float)this._requestedGrainAmount);
				this._currentLiveStockAmount = (int)MathF.Clamp((float)this._currentLiveStockAmount, 0f, (float)this._requestedLiveStockAmount);
				this._currentWineAmount = (int)MathF.Clamp((float)this._currentWineAmount, 0f, (float)this._requestedWineAmount);
				JournalLog grainLog = this._grainLog;
				if (grainLog != null)
				{
					grainLog.UpdateCurrentProgress(this._currentGrainAmount);
				}
				JournalLog liveStockLog = this._liveStockLog;
				if (liveStockLog != null)
				{
					liveStockLog.UpdateCurrentProgress(this._currentLiveStockAmount);
				}
				JournalLog wineLog = this._wineLog;
				if (wineLog == null)
				{
					return;
				}
				wineLog.UpdateCurrentProgress(this._currentWineAmount);
			}

			// Token: 0x06004830 RID: 18480 RVA: 0x0014F640 File Offset: 0x0014D840
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this._playerDeclaredWarQuestLogText, this._questCanceledWarDeclaredLog, false);
			}

			// Token: 0x06004831 RID: 18481 RVA: 0x0014F658 File Offset: 0x0014D858
			public override void OnFailed()
			{
				this.RelationshipChangeWithQuestGiver = -2;
			}

			// Token: 0x06004832 RID: 18482 RVA: 0x0014F662 File Offset: 0x0014D862
			protected override void OnCompleteWithSuccess()
			{
				base.AddLog(this._successQuestLogText, false);
			}

			// Token: 0x06004833 RID: 18483 RVA: 0x0014F672 File Offset: 0x0014D872
			protected override void OnTimedOut()
			{
				this.OnFailed();
				base.AddLog(this._failQuestLogText, false);
			}

			// Token: 0x06004834 RID: 18484 RVA: 0x0014F688 File Offset: 0x0014D888
			public override void OnCanceled()
			{
			}

			// Token: 0x040018BD RID: 6333
			[SaveableField(10)]
			private int _requestedGrainAmount;

			// Token: 0x040018BE RID: 6334
			[SaveableField(20)]
			private int _requestedLiveStockAmount;

			// Token: 0x040018BF RID: 6335
			[SaveableField(30)]
			private int _requestedWineAmount;

			// Token: 0x040018C0 RID: 6336
			[SaveableField(40)]
			private int _currentGrainAmount;

			// Token: 0x040018C1 RID: 6337
			[SaveableField(50)]
			private int _currentLiveStockAmount;

			// Token: 0x040018C2 RID: 6338
			[SaveableField(60)]
			private int _currentWineAmount;

			// Token: 0x040018C3 RID: 6339
			[SaveableField(70)]
			private JournalLog _grainLog;

			// Token: 0x040018C4 RID: 6340
			[SaveableField(80)]
			private JournalLog _liveStockLog;

			// Token: 0x040018C5 RID: 6341
			[SaveableField(90)]
			private JournalLog _wineLog;
		}

		// Token: 0x020005FD RID: 1533
		public class ArmyNeedsSuppliesIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06004838 RID: 18488 RVA: 0x0014F6B1 File Offset: 0x0014D8B1
			public ArmyNeedsSuppliesIssueTypeDefiner() : base(585800)
			{
			}

			// Token: 0x06004839 RID: 18489 RVA: 0x0014F6BE File Offset: 0x0014D8BE
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssue), 1, null);
				base.AddClassDefinition(typeof(ArmyNeedsSuppliesIssueBehavior.ArmyNeedsSuppliesIssueQuest), 2, null);
			}
		}
	}
}
